<!-- 搜索房源 -->
<template>
  <div class="box">
    <heads></heads>
    <tools></tools>
    <div class="tit1">
      <div class="list" style="margin-top:0">
        <div class="li" style="cursor: pointer" @click="() => {
          $router.push('/');
        }
          ">
          <img src="../../assets/logo.png" />
        </div>
        <div class="sousuo">
          <input type="text" v-model="HousesPage.keyword" @keyup.enter="search" placeholder="请输入关键字搜索" />
          <p class="el-icon-search" @click="search"></p>
        </div>
        <!-- <div class="but">下载帮帮同城app</div> -->
        <downloadAppBtn></downloadAppBtn>
      </div>
    </div>
    <div class="list">
      <div style="
          display: flex;
          color: #333;
          font-size: 32px;
          font-weight: 600;
          width: 1200px;
          margin: auto;
          margin-bottom: 24px;
        ">
        共找到
        <div style="color: #1cbbb4; margin: 0 5px">{{ housetotal }}</div>
        个结果
      </div>
      <div class="houseData">
        <!-- 从大主页跳转 -->
        <template v-if="indexOf == 1">
          <div>
            <template v-for="(item, index) in houseList">
              <template v-if="item.category == '2'">
                <div class="traffic" :key="'01' + index">
                  <bbcz-item :item="item" @details="details" @toAgent="toAgent" @shopdetails="shopdetails"></bbcz-item>
                </div>
              </template>
              <template v-if="item.category == '1'">
                <div style="
                    width: 1200px;
                    display: flex;
                    margin-bottom: 24px;
                    padding-bottom: 24px;
                    border-bottom: 1px solid #e0e0e0;
                    justify-content: space-between;
                  " :key="'02' + index">
                  <div style="
                      width: 300px;
                      height: 200px;
                      background-color: #aaaaaa26;
                      border-radius: 10px;
                    ">
                    <img :src="item.displayDiagram
                      ? item.displayDiagram
                      : item.houseImage.split('|')[0]
                      " style="width: 100%; height: 100%; object-fit: contain" />
                  </div>
                  <div style="
                      width: 700px;
                      display: flex;
                      flex-direction: column;
                      justify-content: space-between;
                    ">
                    <div @click="details(item)" style="
                        font-size: 24px;
                        cursor: pointer;
                        font-weight: 600;
                        color: #333;
                        display: -webkit-box;
                        overflow: hidden;
                        text-overflow: ellipsis;
                        word-wrap: break-word;
                        white-space: normal !important;
                        -webkit-line-clamp: 2;
                        -webkit-box-orient: vertical;
                      ">
                      <tag-view :item="item"></tag-view>{{
                        item.title
                      }}
                    </div>
                    <div style="font-size: 16px; color: #666666; margin-top: 12px">
                      {{ item.region }} {{ item.address }}
                    </div>
                    <div style="font-size: 16px; color: #666666; margin-top: 12px">
                      {{ item.houseType }} {{ item.area }}㎡ {{ item.floor }}
                    </div>
                    <div style="flex-grow: 1"></div>
                    <div style="display: flex; width: 700px; align-items: center">
                      <img style="
                          width: 31px;
                          height: 31px;
                          border-radius: 31px;
                          cursor: pointer;
                        " @click="toAgent(item)" :src="item.image ||
                          item.userImage ||
                          'https://pic.bangbangtongcheng.com/static/my/header.png'
                          " />

                      <div @click="toAgent(item)" style="
                          color: #666666;
                          font-size: 16px;
                          max-width: 300px;
                          margin: 0 10px;
                          cursor: pointer;
                          white-space: nowrap;
                          overflow: hidden;
                          text-overflow: ellipsis;
                        ">
                        {{ item.nikeName || "未命名用户" }}
                      </div>
                      <div @click="shopdetails(item)" style="
                          padding: 2px 5px;
                          color: #64b6a8;
                          border: #64b6a8 1px solid;
                          border-radius: 4px;
                          max-width: 240px;
                          cursor: pointer;
                          font-size: 16px;
                          white-space: nowrap;
                          overflow: hidden;
                          text-overflow: ellipsis;
                        ">
                        {{ item.shopName || "个人房源" }}
                      </div>
                    </div>
                  </div>
                  <div style="
                      width: 160px;
                      display: flex;
                      flex-direction: column;
                      align-items: flex-end;
                      justify-content: center;
                    ">
                    <template v-if="item.transaction_type == 1 || item.transactionType == 1">
                      <div style="font-size: 30px; color: #e00000">
                        {{ item.price }}元
                      </div>
                    </template>
                    <template v-if="item.transaction_type == 2 || item.transactionType == 2">
                      <div style="font-size: 30px; color: #e00000">
                        {{ item.price }}万
                      </div>
                      <div style="font-size: 16px; color: #333333">
                        {{ (item.price / item.area).toFixed(2) }}元/㎡
                      </div>
                    </template>
                  </div>
                </div>
              </template>
            </template>
          </div>
        </template>
        <!-- 从车主首页跳转 -->
        <template v-else-if="indexOf == 2">
          <template v-for="(item, index) in houseList">
            <div class="traffic" :key="'03' + index" v-if="!item.entryName">
              <bbcz-item :item="item" @details="details" @toAgent="toAgent" @shopdetails="shopdetails"
                :key="'04' + index"></bbcz-item>
            </div>
            <div class="li" :key="'03' + index" v-if="item.entryName">
              <img class="biao" @click="details(item)" style="
                  object-fit: contain;
                  cursor: pointer;
                  background-color: #00000033;
                " :src="item.coverPhoto ? item.coverPhoto : $img + item.houseImageDiv
                  " />
              <div class="fwxm">
                <div class="t_1" style="cursor: pointer" @click="details(item)">
                  {{ item.entryName }}
                </div>
                <div class="t_2 " style="cursor: pointer" @click="details(item)">
                  <span style="margin-right: 5px" class="line7">{{
                    item.entryDescription
                  }}</span>
                </div>
              </div>
            </div>
          </template>
        </template>
        <!-- 从经销商跳转过来的 -->
        <template v-else-if="indexOf == 3">
          <template v-for="(item, index) in houseList">
            <div class="traffic" :key="'05' + index">
              <img class="biao" @click="details(item)" style="
                  object-fit: contain;
                  cursor: pointer;
                  background-color: #00000033;
                " :src="item.houseImage ? item.houseImage : $img + item.houseImageDiv
                  " />
              <div class="name">
                <div class="t_1" style="cursor: pointer" @click="details(item)">
                  <tag-view :item="item"></tag-view>{{ item.title }}
                </div>
                <div class="t_2" style="cursor: pointer" @click="details(item)">
                  <span style="margin-right: 5px">
                    {{ item.region }}{{ item.address }}</span>
                </div>
              </div>
            </div>
          </template>
        </template>
        <div v-if="housetotal == 0" style="height:450px;padding-top:120px;box-sizing: border-box;">
          <el-empty></el-empty>
        </div>
        <div class="fenye">
          <el-pagination @current-change="HousesCurrentChange" background layout="prev, pager, next" :total="housetotal"
            :current-page="HousesPage.PageNo" :page-size="HousesPage.pageSize"></el-pagination>
        </div>
      </div>
    </div>
    <floor></floor>
    <div class="gotop" @click="toTop" v-show="showToTop" style="left: calc(100vw / 2 + 600px);;">
      <img src="@/assets/top.png" />返回顶部
    </div>
  </div>
</template>

<script>
import floor from "../../components/floor";
import heads from "../../components/head";
import houseList from "../../components/houseList.vue";
import tools from "../../components/tools.vue";
import BbczItem from "./comp/bbcz-item.vue";
export default {
  components: {
    floor,
    heads,
    houseList,
    tools,
    BbczItem
  },
  data() {
    return {
      olds: "3",
      HousesPage: {
        pageSize: 10,
        pageNo: 1,
        keyword: "",
        upStatus: 1,
        examineStatus: 2,
        isLz: "0"
      },
      housetotal: 0,
      houseList: [],
      indexOf: 3,
      pageSize: 10,
      pageNo: 1,
      pageCount: 1
    };
  },
  created() {
    this.HousesPage.keyword = this.$route.query.search || "";
    this.indexOf = this.$route.query.index || 1;
    this.getData();
    // this.getHouseInfo()
    // this.getDictionaries()
  },
  methods: {
    getData() {
      if (this.indexOf == 1) {
        this.bigHomePageSearch();
      } else if (this.indexOf == 2) {
        this.homeSearch();
      } else {
        this.bigHomePageSearch();
      }
    },
    // 经销商搜索
    getDealerByConditions() {
      this.$getHttp("/api/mobile/vehicleOwner/getDealerByConditions", {
        searchKeyword: this.HousesPage.keyword,
        pageNo: this.HousesPage.pageNo,
        pageSize: this.HousesPage.pageSize
      });
    },

    // 大主页搜索
    bigHomePageSearch() {
      this.$getHttp("/api/mobile/vehicleOwner/bigHomePageSearch", {
        searchKeyword: this.HousesPage.keyword,
        pageNo: this.HousesPage.pageNo,
        pageSize: this.HousesPage.pageSize
      }).then(data => {
        if (data.code == 200) {
          data.mainHomePageList.pageList.forEach(e => {
            if (e.hasOwnProperty("floor")) {
              if (e.floor.indexOf("|") == -1) {
                e.floor = "";
              } else {
                e.floor =
                  e.floor.split("|")[0] +
                  "层/" +
                  "共" +
                  e.floor.split("|")[1] +
                  "层";
              }
            }
            if (!e.hasOwnProperty("shop_name")) {
              e.shop_name = "个人房源";
            }
            e.imagestate = true;
            if (!e.hasOwnProperty("image")) {
              e.imagestate = false;
            }
            if (e.hasOwnProperty("createDate")) {
              e.showYear = new Date(e.createDate || e.updateDate).getFullYear();
            }
          });
          // data.mainHomePageList.pageList.sort(function (a, b) {
          //   console.log(
          //     a.update_date || a.create_date - b.update_date || b.create_date
          //   );
          //   return (
          //     (b.update_date || b.create_date) -
          //     (a.update_date || a.create_date)
          //   );
          // });

          this.houseList = data.mainHomePageList.pageList;
          console.log("houseListhouseListhouseList", this.houseList);
          this.housetotal = data.mainHomePageList.pageCount;
          // this.pageCount = data.mainHomePageList.pageCount
        }
      });
    },
    // 车源页搜索
    homeSearch() {
      this.$getHttp("/api/mobile/vehicleOwner/homeSearch", {
        searchKeyword: this.HousesPage.keyword,
        pageNo: this.HousesPage.pageNo,
        pageSize: this.HousesPage.pageSize
      }).then(data => {
        if (data.code == 200) {
          data.homePageList.pageList.forEach(e => {
            if (e.hasOwnProperty("createDate")) {
              e.showYear = new Date(e.createDate || e.updateDate).getFullYear();
            }
          });
          // data.homePageList.pageList.sort(function (a, b) {
          //   console.log(
          //     a.update_date || a.create_date - b.update_date || b.create_date
          //   );
          //   return (
          //     (b.update_date || b.create_date) -
          //     (a.update_date || a.create_date)
          //   );
          // });

          this.houseList = data.homePageList.pageList;
          console.log("houseListhouseListhouseList", this.houseList);
          this.housetotal = data.homePageList.pageCount;
          // this.pageCount = data.mainHomePageList.pageCount
        }
      });
    },
    getHouseInfo() {
      this.$getHttp("/mob/home/getHouseInfo", this.HousesPage).then(data => {
        if (data.code == 200) {
          data.list.forEach(e => {
            if (e.hasOwnProperty("FLOOR")) {
              if (e.floor.indexOf("|") == -1) {
                e.floor = "";
              } else {
                e.floor =
                  e.floor.split("|")[0] +
                  "层/" +
                  "共" +
                  e.floor.split("|")[1] +
                  "层";
              }
            }
            if (!e.hasOwnProperty("shop_name")) {
              e.shop_name = "个人房源";
            }
            e.imagestate = true;
            if (!e.hasOwnProperty("image")) {
              e.imagestate = false;
            }
          });
          data.list.sort(function (a, b) {
            console.log(
              a.update_date || a.create_date - b.update_date || b.create_date
            );
            return (
              (b.update_date || b.create_date) -
              (a.update_date || a.create_date)
            );
          });

          this.houseList = data.list;
          this.housetotal = data.count;
          console.log(data);
        }
      });
    },
    getDictionaries() {
      this.$getHttp("/mob/home/getDictionaries", { type: "8,9,10,1" }).then(
        data => {
          if (data.code == 200) {
            data.list.forEach(e => {
              if (e.type == 8) this.type8.push(e);
              if (e.type == 9) this.type9.push(e);
              if (e.type == 10) this.type10.push(e);
              if (e.type == 1) this.type1.push(e);
            });
          }
        }
      );
    },
    search() {
      if (this.searchtext != "") {
        this.HousesPage.keyword = this.searchtext
          ? this.searchtext
          : this.HousesPage.keyword;
        this.HousesPage.pageNo = 1;
        // this.getHouseInfo()
        this.getData();
      }
    },
    //页数改变时触发
    HousesCurrentChange(e) {
      this.scrollToElement(document.querySelector(".tit1"));
      this.HousesPage.pageNo = e;
      this.getData();
    },
    details(item) {
      // 车源
      if (item.vehicleType) {
        this.openUrl({
          path: "/index/newSourceDetails",
          query: {
            id: item.id
          }
        });
      } else if (item.entryName) {
        this.openUrl({
          path: "/index/serviceDetails",
          query: {
            id: item.id
          }
        });
      } else if (item.transactionType == 1) {
        this.openUrl({
          path: "/index/leaseDetails",
          query: {
            id: item.id
          }
        });
      } else {
        // 新房
        this.openUrl({
          path: "/index/newHouseDetails",
          query: {
            id: item.id
          }
        });
      }
    },
    toAgent(item) {
      if (this.indexOf == 1) {
        if (item.category == "2") {
          //车源
          if (!item.isAgent && !item.storeId) {
            this.openUrl({
              path: "/index/goldConsultant",
              query: {
                id: item.publisherId || item.id
              }
            });
            return;
          }
          this.openUrl({
            path: "/index/goldConsultant",
            query: {
              id: item.publisherId
            }
          });
        } else if (item.category == "1") {
          if (!item.isAgent && !item.shopId) {
            this.openUrl({
              path: "/index/goldConsultant",
              query: {
                id: item.user_id || item.userId || item.publisherId || item.id
              }
            });
            return;
          }
          this.openUrl({
            path: "/index/goldConsultant",
            query: {
              id: item.publisherId
            }
          });
        }
      } else if (this.indexOf == 2) {
        if (!item.isAgent && !item.storeId) {
          this.openUrl({
            path: "/index/goldConsultant",
            query: {
              id: item.publisherId || item.id
            }
          });
          return;
        }
        this.openUrl({
          path: "/index/goldConsultant",
          query: {
            id: item.publisherId
          }
        });
      }
    },
    shopdetails(item) {
      if (this.indexOf == 1) {
        if (item.category == "2") {
          if (item.shopName || item.storeName) {
            const routeLink = this.$router.resolve({
              path: "/index/newDealerDetails?id=" + item.storeId
            });
            window.open(routeLink.href, "_blank");
          } else {
            this.$message({
              message: "个人车源！",
              type: "error",
              offset: 120,
              duration: 2000
            });
          }
        } else if (item.category == "1") {
          if (!item.shop_name) {
            this.$message({
              message: "个人房源！",
              type: "error",
              offset: 120,
              duration: 2000
            });
          } else {
            const routeLink = this.$router.resolve({
              path: "/index/ShopDetails?id=" + item.storeId
            });
            window.open(routeLink.href, "_blank");
          }
        }
      } else if (this.indexOf == 2) {
        if (item.distributor) {
          const routeLink = this.$router.resolve({
            path: "/index/newDealerDetails?id=" + item.distributor.id
          });
          window.open(routeLink.href, "_blank");
        } else {
          this.$message({
            message: "个人车源！",
            type: "error",
            offset: 120,
            duration: 2000
          });
        }
      }
    }
  }
};
</script>

<style lang="less" scoped>
.box {
  position: relative;
  width: 100%;
  // max-width: 1920px;
  min-width: 1200px;
  padding-bottom: 200px;
}

.tit1 {
  width: 100%;
  height: 120px;
  background-color: #f2f2f2;

  .list {
    width: 1200px;
    margin-left: 50%;
    // padding-top: 32px;
    transform: translateX(-50%);
    background-color: #f2f2f2;

    div {
      display: inline-block;
      vertical-align: middle;
      font-size: 20px;
      color: #333333;
      margin-right: 40px;
      cursor: pointer;
    }

    .li {
      font-size: 28px;
      color: #64b6a8;
      margin-right: 60px;
      margin-top: 32px;
      padding-bottom: 24px;
      margin-bottom: 0;
      border-bottom: 0;

      img {
        /* width: 60px;
				height: 60px; */
      }

      span {
        vertical-align: middle;
      }
    }

    .sousuo {
      position: relative;
      display: inline-block;
      vertical-align: middle;
      width: 380px;
      height: 50px;
      background: #ffffff;
      border-radius: 4px;
      font-size: 18px;
      overflow: hidden;

      input {
        width: 300px;
        height: 55px;
        line-height: 55px;
        text-indent: 16px;
        font-size: 18px;
      }

      img {
        width: 25px;
        height: 25px;
        margin-left: 20px;
        cursor: pointer;
      }

      p {
        position: absolute;
        top: 0;
        right: 0;
        width: 80px;
        height: 55px;
        background-color: #64b6a8;
        text-align: center;
        line-height: 55px;
        font-size: 24px;
        cursor: pointer;
        color: #ffffff;
      }
    }

    .but {
      display: inline-block;
      width: 200px;
      height: 50px;
      background: #64b6a8;
      border-radius: 6px;
      text-align: center;
      line-height: 50px;
      color: #fff;
    }
  }
}

.list {
  margin-top: 30px;

  .houseData {
    width: 1200px;
    margin: 0 auto;

    .traffic {
      position: relative;
      padding-bottom: 24px;
      margin-bottom: 24px;
      border-bottom: 1px solid #e0e0e0;
      height: 225px;

      .biao {
        width: 300px;
        height: 200px;
        border-radius: 10px;
      }

      .name {
        display: inline-block;
        vertical-align: top;
        margin-left: 24px;
        position: relative;
        height: 200px;
        width: 700px;

        .t_1 {
          font-size: 24px;
          cursor: pointer;
          font-weight: 600;
          color: #000;
        }

        .t_2 {
          font-size: 16px;
          color: #666666;
          margin-top: 12px;
        }

        .t_3 {
          font-size: 16px;
          color: #666666;
          margin-top: 12px;
        }

        .t_4 {
          position: absolute;
          font-size: 16px;
          color: #666666;
          bottom: 0;
          left: 0;
          white-space: nowrap;

          img {
            width: 31px;
            height: 31px;
            border-radius: 31px;
          }

          div {
            display: inline-block;
            padding: 0px 5px;
            height: 30px;
            background: #ffffff;
            border: 1px solid #64b6a8;
            border-radius: 4px;
            text-align: center;
            line-height: 30px;
            margin-left: 24px;
            color: #64b6a8;
          }
        }
      }

      .qian {
        position: absolute;
        top: 62px;
        right: 0;

        .p1 {
          font-size: 30px;
          color: #e00000;
          text-align: center;
        }

        .p2 {
          font-size: 16px;
          color: #333333;
          text-align: center;
        }
      }
    }

    .fenye {
      width: 100%;
      height: 50px;
      text-align: center;
      margin-bottom: 50px;
    }
  }
}

.li {
  position: relative;
  padding-bottom: 24px;
  margin-bottom: 24px;
  border-bottom: 1px solid #e0e0e0;

  .biao {
    width: 300px;
    height: 200px;
    border-radius: 10px;
  }

  .fwxm {
    display: inline-block;
    vertical-align: top;
    margin-left: 24px;
    position: relative;
    height: 200px;
    width: 700px;

    .t_1 {
      font-size: 24px;
      cursor: pointer;
      font-weight: 600;
      color: #64b6a8;
    }

    .t_2 {
      font-size: 16px;
      color: #666666;
      margin-top: 12px;
    }
  }

  .name {
    display: inline-block;
    vertical-align: top;
    margin-left: 24px;
    position: relative;
    height: 200px;
    width: 700px;

    .t_1 {
      font-size: 24px;
      cursor: pointer;
      font-weight: 600;
    }

    .t_2 {
      font-size: 16px;
      color: #666666;
      margin-top: 12px;
    }

    .t_3 {
      font-size: 16px;
      color: #666666;
      margin-top: 12px;
    }

    .t_4 {
      position: absolute;
      font-size: 16px;
      color: #666666;
      bottom: 0;
      left: 0;
      white-space: nowrap;

      img {
        vertical-align: top;
        width: 31px;
        height: 31px;
        border-radius: 31px;
      }

      div {
        display: inline-block;
        //width: 90px;
        padding: 0px 5px;
        height: 30px;
        background: #ffffff;
        border: 1px solid #64b6a8;
        border-radius: 4px;
        text-align: center;
        line-height: 30px;
        margin-left: 24px;
        color: #64b6a8;
      }
    }
  }

  .qian {
    position: absolute;
    top: 62px;
    right: 0;

    .p1 {
      //width: 120px;
      //font-size: 32px;
      font-size: 30px;
      color: #e00000;
      text-align: center;
    }

    .p2 {
      //width: 120px;
      //font-size: 18px;
      font-size: 16px;
      color: #333333;
      text-align: center;
    }
  }
}
</style>
